function _pay(_e) {
	var orderNo = $(_e).attr('id');
	$.ajax({
		url: '/park/road/data/getPayInfo?orderNo=' + orderNo + '&orderType=2',
		type: 'get',
		dataType: 'json',
		success: function(res) {
			if ('200' == res.code) {
				localStorage.setItem("payHours", res.data.park.parkingHours);
				localStorage.setItem("amount", res.data.park.totalAmount);
				localStorage.setItem("tradeNo", res.data.pay.order_no);
				var htmlStr = "<input name=jsonParams id=jsonParams value=" + JSON.stringify(res.data.pay) + " />";
				$('#pay').append(htmlStr);
				$('#pay').submit();
			}
		}
	})
}
function _getInvoice(_e) {
	var tradeNo = $(_e).attr('id');
	$.ajax({
		url: '/park/road/data/getInvoiceUrl',
		type: 'post',
		data: 'tradeNo=' + tradeNo + '&carLicense=' + cph,
		dataType: 'json',
		success: function(res) {
			location.href = res.data.attr.url;
		}
	})
}
function goBack() {
	location.href = "/park/r_logs";
}
function _getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) return unescape(r[2]); return null; //返回参数值
}
var cph;
$(function() {
	var wx_order_id = _getUrlParam('wx_order_id');
	var orderNo = _getUrlParam('orderNo');
	var orderno = '', amount = '';
	var payHours = '';
	if (wx_order_id  != null &&  wx_order_id != '') {
		layer.open({
			content: '支付成功！',
			btn: '我知道了',
			yes:  function() {
				$.ajax({
					url: '/park/getOrderInfo',
					type: 'post',
					data: 'orderNo=' + orderNo,
					dataType:  'json',
					success: function(res) {
						orderno = res.data.outNo;
						amount = res.data.pay;
						payHours = res.month;
						$.ajax({
							url: '/park/road/data/saveTrade',
							type: 'post',
							data: 'orderNo=' + orderNo + '&orderno='+orderno +  '&amount=' +  ount +   '&payHours='  + payHours,
							dataType: 'json',
							success: function(res) {
								location.href = '/park/r_orderDetail?orderNo='  + orderNo;
							}
						})
					}
				})
			}
		})	
	} else {
		$.ajax({
			url: '/park/road/data/getOrderDetail',
			type: 'post',
			data: 'orderNo=' + orderNo,
			dataType: 'json',
			success: function(res) {
				if (res.data.status != '0') {
					layer.open({
						content: res.data.msg,
						skin: 'msg',
						time: 2
						//2秒后自动关闭
					});
				} else {
					if (res.data.attr.result[0].parkingTime == null) {
						res.data.attr.result[0].parkingTime = '';
					}
					cph = res.data.attr.result[0].carLicense;
					var time = res.data.attr.result[0].startTime;
					res.data.attr.result[0].startTime = time.substring(0, 4) + '-' + time.substring(4, 6) + '-' + time.substring(6, 8) + ' ' + time.substring(8, 10) + ':' + time.substring(10, 12) + ':' + time.substring(12, 14)
					var time = res.data.attr.result[0].endTime;
					if (time != null && time != ''){
						res.data.attr.result[0].endTime = time.substring(0, 4)  + '-' + time.substring(4, 6)  + '-' + time.substring(6, 8) + ' ' + time.substring(8, 10) +':' +  time.substring(10, 12)  + ':' + time.substring(12, 14)
					}
					res.data.attr.result[0].need = res.data.attr.result[0].totalAmount - res.data.attr.result[0].havePayMoney;
					if (res.data.attr.result[0].endTime  == null) {
						res.data.attr.result[0].endTime = '';
					}
					new Vue({
						el: '#detail',
						data: {
							item: res.data.attr.result[0]
						}
					})
					$.ajax({
						url: '/park/road/data/getTrade',
						type: 'post',
						data: 'orderNo=' + orderNo,
						dataType: 'json',
						success: function(res) {
							if (res.data.status == '0' && res.data.attr.result != null) {
								$('#data').show();
								new Vue({
									el: '#data',
									data: {
										datas: res.data.attr.result
									}
								})
							}
						}
					})
				}
			}
		})
	}
})